package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import neusoft.yuejian_11.activity.PrizeDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.PrizeBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.PrizeListViewHolder;

import com.squareup.picasso.Picasso;

import java.util.List;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by NEUSOFT on 2017/10/1.
 */

public class PrizeListAdapter extends BaseListAdapter {
    public PrizeListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_prize,parent,false);
        PrizeListViewHolder holder=new PrizeListViewHolder(itemView);
        return holder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        PrizeListViewHolder prizeListViewHolder=(PrizeListViewHolder) holder;
        final PrizeBean prizeBean = (PrizeBean)data.get(position);

        final String prizename =prizeBean.getG_name();
        String prizeinfo=prizeBean.getG_infos();
        String prizeyundz=prizeBean.getG_values();
        final int  giftId=prizeBean.getG_id();
        String pic = BASE_URI+"giftpic/"+prizeBean.getG_pic();
        Picasso.with(context)
                .load(pic)
                .placeholder(R.drawable.ic_cook_holder)
                .error(R.drawable.ic_cook_holder_error)
                .into(PrizeListViewHolder.imageView);
        prizeListViewHolder.prizenameView.setText(prizename);
        prizeListViewHolder.prizeinfoView.setText(prizeinfo);
        prizeListViewHolder.prizeyundzView.setText(prizeyundz);

        prizeListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,PrizeDetailActivity.class);
                intent.putExtra("g_id",giftId);
                context.startActivity(intent);

            }
        });
    }

}
